package com.wlh.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wlh.common.PageVo;
import com.wlh.common.R;
import com.wlh.entity.ProjectMessage;
import com.wlh.service.ProjectMessageService;

@CrossOrigin
@RestController
public class H2Controller {

	@Autowired
	ProjectMessageService projectMessageService;

	Logger log = LoggerFactory.getLogger(H2Controller.class);

	@GetMapping("/hello")
	public String hello(String i) {

		log.info("这是一条log.info..............");

		try {
			if (i != null) {
				int k = 1 / 0;
			}
		} catch (Exception e) {
			log.error("除数为0",e);
		}
		return "操作成功";
	}

	@GetMapping("/hello2")
	public String hello2(String i) {

		i.toString();
		return "操作成功";
	}

	@GetMapping("/searchByProjectNo")
	public List<ProjectMessage> searchByProjectNo(String projectNo, String status) {
		System.out.println("项目编号：" + projectNo);
		System.out.println((status.equals("2")) ? "构建镜像" : (status.equals("3")) ? "部署镜像" : status);
		return projectMessageService.searchByProjectNo(projectNo, status);
	}

	@GetMapping("/search")
	public Object search(PageVo vo, String projectNo) {
		System.out.println("1111");
		IPage<ProjectMessage> ipageVo = projectMessageService.search(vo, projectNo);
		List<ProjectMessage> list = ipageVo.getRecords();
		R r = new R(list);
		r.setCount(ipageVo.getSize());
		return r;
	}

	@GetMapping("/save")
	public Object save(ProjectMessage vo) {
		vo.setStatus("1");
		projectMessageService.save(vo);
		return new R();
	}

	@GetMapping("/edit")
	public Object edit(ProjectMessage vo) {
		ProjectMessage entity = projectMessageService.getById(vo.getId());
		entity.setStatus(vo.getStatus());
		projectMessageService.updateById(entity);
		return new R();
	}

	@GetMapping("/delete")
	public Object edit(Long id) {
		projectMessageService.removeById(id);
		return new R();
	}

}
